"""
Case Type   : Compatibility
Case Name   : 在非当前会话使用prepare语句
Create At   : 2024/10/17
Owner       : liu-tong-8848
Description :
              1.在当前会话创建prepare语句
              2.新开session连接数据库execute
              3.清理环境
Expect      :
              1.成功
              2.合理报错
              3.清理环境成功
History     :
"""

import os
import unittest

from testcase.utils.CommonSH import CommonSH
from testcase.utils.Constant import Constant
from testcase.utils.Logger import Logger
from yat.test import Node


class SQL(unittest.TestCase):
    def setUp(self):
        self.log = Logger()
        self.Constant = Constant()
        self.primary_sh = CommonSH('PrimaryDbBmode')
        self.db_user_node = Node(node='PrimaryDbBmode')

    def test_add_dimension(self):
        self.log = Logger()
        self.log.info(f'-----{os.path.basename(__file__)} start-----')
        step1 = '--step1:创建prepare语法中preparable_stmt参数不带引号;expect:合理报错'
        self.log.info(step1)
        sql = "drop table if exists t_prepare_014;"
        self.log.info(sql)
        result = self.primary_sh.execut_db_sql(sql)
        self.log.info(result)
        self.assertIn(self.Constant.DROP_TABLE_SUCCESS, result, "执行失败" + step1)
        sql = "prepare test_prepare_014 from create table t_prepare_014(c1 int);"
        self.log.info(sql)
        result = self.primary_sh.execut_db_sql(sql)
        self.log.info(result)
        self.assertIn("ERROR", result, "执行失败" + step1)

    def tearDown(self):
        step2 = 'step2:清理环境 expect:清理环境成功'
        self.log.info(step2)
        self.log.info(f'-----{os.path.basename(__file__)} end-----')
